package us.gaaoc.framework.webapp.backingbeans.agent;

import java.util.List;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.transaction.annotation.Transactional;

import us.gaaoc.framework.model.CaseRecordHistory;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

/**
 * 
 * @author hea
 * @date May 3, 2006
 * @version: GAJE 1.5
 * 
 */
public class CaseRecordHistoryPage extends BaseBackingBean {

	/**
	 * Property
	 */
	private DataModel historyDataTable;

	/**
	 * Constructor
	 *
	 */
	public CaseRecordHistoryPage() {
		this.loadData();
	}

	/**
	 * This method loads the data from database
	 *
	 */
	private void loadData() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		String caseUuid = (String) sessionMap.get("caseUuid");
		String courtUuid = (String) sessionMap.get("courtUuid");
		List<CaseRecordHistory> historyList = this.getModelFacade()
				.findHistoryByCaseRecordID(caseUuid, courtUuid);
		historyDataTable = new ListDataModel();
		historyDataTable.setWrappedData(historyList);
	}
	
	/**
	 * Getter for property historyDataTable
	 * @return historyDataTable
	 */
	public DataModel getHistoryDataTable() {
		return historyDataTable;
	}

	/**
	 * Setter for property historyDataTable
	 * @param historyDataTable
	 */
	public void setHistoryDataTable(DataModel historyDataTable) {
		this.historyDataTable = historyDataTable;
	}

	/**
	 * This method navigates user to the previous page
	 * @return String
	 */
	public String back() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		String fromPage = (String) sessionMap.get("from");
		sessionMap.remove("from");
		sessionMap.remove("caseUuid");

		if (fromPage.equalsIgnoreCase("AllFilingsTablePage")) {
			return "agentHome";
		} 
			else if(fromPage.equalsIgnoreCase("trashcanPage")) {
				return "trashcanPage";
			}			
			else if (fromPage.equalsIgnoreCase("AgentFilingsTablesPage")) 
				return "agentHome";
			else if (fromPage.equalsIgnoreCase("searchPage")) {
				sessionMap.put("from", "AgentFilingsTablesPage");
				return "searchPage";
			}
			else return "";
	}
}
